var reportUrl = "";
var isViewReady = false;

//@Bind view.onReady
!function(self, arg, dsCondition, dsWarehouse, actionReportUrl, tabs) {
	var condition = dsCondition.insert();
	actionReportUrl.execute(function(result){
		reportUrl = result;
	});
	dsWarehouse.flush();
	var warehouses = dsWarehouse.getData();
	if(warehouses.entityCount > 0){
		var warehouse = warehouses.getFirst();
		condition.set("warehouseUid", warehouse.get("uuid"));
		condition.set("warehouseName", warehouse.get("warehouseName"));
	}
	isViewReady = true;
	query(dsCondition, tabs);
}

// @Bind #btnQuery.onClick
!function(self, arg, dsCondition, tabs) {
	query(dsCondition, tabs);
}

function query(dsCondition, tabs){
	var condition = dsCondition.getData("#");
	var warehouseUid = "";
	var drawingId = "";
	var partName = "";
	var batchNum = "";
	if(condition.get("warehouseUid") != null){
		warehouseUid = condition.get("warehouseUid");
	}
	if(condition.get("drawingId") != null){
		drawingId = condition.get("drawingId");
	}
	if(condition.get("partName") != null){
		partName = condition.get("partName");
	}
	if(condition.get("batchNum") != null){
		batchNum = condition.get("batchNum");
	}
	
	var tab = tabs.get("currentTab");
	if(tab.get("name") == "ioRecord"){
		var url = reportUrl + "/sree/Reports?op=frameReplet&name=inv/InvWasteBook_QueryTool&WAREHOUSEUID=" + warehouseUid + "&DRAWINGID=" + drawingId + "&PARTNAME=" + partName + "&BATCHNUM=" + batchNum;
//		alert(url);
		tab.set("path", url);
	}else if(tab.get("name") == "invInfo"){
		var url = reportUrl + "/sree/Reports?op=frameReplet&name=inv/invAccountBook_Query&WAREHOUSEUID=" + warehouseUid + "&DRAWINGID=" + drawingId + "&PARTNAME=" + partName + "&BATCHNUM=" + batchNum;
//		alert(url);
		tab.set("path", url);
	}
}

//@Bind #tabs.onTabChange
!function(self, arg, dsCondition) {
	if(isViewReady == true){
		query(dsCondition, self);
	}
}